package eu.dicode.analysis.demonstrator;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import eu.dicode.analysis.demonstrator.model.HomeCommand;
import eu.dicode.analysis.demonstrator.util.CommandPopulator;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

  private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
  private final CommandPopulator pop;

  public HomeController() throws IOException {
    this.pop = new CommandPopulator();
  }

  /**
   * Simply selects the home view to render by returning its name.
   */
  @RequestMapping(value = "/home", method = RequestMethod.GET)
  public String home(final Model model) {
    final HomeCommand homeCommand = new HomeCommand();
    this.pop.populate(homeCommand);
    model.addAttribute("homeCommand", homeCommand);
    return "home";
  }
}
